<template>
  <el-aside>
    <div id="sidebar" class="d-flex fulled-h">
      <div class="sidebar-view fulled-h t-center">
        <div
          class="sidebar-view-toggle py-16 mt-16 pointer"
          :class="{ active: activeView === '组件' }"
          @click="toggleView('组件')"
        >
          <i class="icon icon-widget"></i>
          <div class="mt-8">组件</div>
        </div>
        <div
          id="sidebar-page-btn"
          class="sidebar-view-toggle py-16 pointer"
          :class="{ active: activeView === '页面' }"
          @click="toggleView('页面')"
        >
          <i class="icon icon-layout"></i>
          <div class="mt-8">页面</div>
        </div>
      </div>
      <el-drawer-transition>
        <div v-show="collapse">
          <el-scrollbar>
            <!-- 组 件 -->
            <WidgetView v-show="activeView === '组件'" />
            <!-- 页 面 -->
            <PageView v-show="activeView === '页面'" ref="PageView" />
          </el-scrollbar>
        </div>
      </el-drawer-transition>
    </div>
    <el-tooltip placement="top">
      <template #content>{{ collapse ? '收起' : '展开' }}</template>
      <div class="toggler" @click="collapse = !collapse">
        <div class="toggler-img" :class="{ collapse }"></div>
      </div>
    </el-tooltip>
  </el-aside>
</template>

<script>
  import WidgetView from './WidgetView';
  import PageView from './PageView';
  export default {
    components: { WidgetView, PageView },

    data() {
      return {
        activeView: '组件',
        collapse: true
      };
    },

    methods: {
      toggleView(view) {
        this.collapse = true;
        this.activeView = view;
      }
    }
  };
</script>

<style lang="scss" scoped>
  // 侧边栏样式
  .el-aside {
    position: relative;
    overflow: visible;
    border-right: 1px solid map-get($bdColors, 'light');
    width: unset !important;

    .sidebar-view {
      border-right: 1px solid map-get($bdColors, 'light');

      .sidebar-view-toggle {
        width: 72px;
        height: 78px;
        color: map-get($colors, 'grey');
        background-clip: content-box;

        .icon {
          width: 24px;
          height: 24px;

          &.icon-layout {
            @include bg('marketing/productEdit/icons/icon-layout.png');
          }

          &.icon-widget {
            @include bg('marketing/productEdit/icons/icon-widget.png');
          }
        }

        &.active {
          color: map-get($colors, 'theme');
          @include bg('marketing/productEdit/icons/activated-left-bar.png');
          background-repeat: no-repeat;
          background-position: left center;
          background-size: auto 48px;

          .icon-layout {
            @include bg('marketing/productEdit/icons/icon-layout-activated.png');
          }

          .icon-widget {
            @include bg('marketing/productEdit/icons/icon-widget-activated.png');
          }
        }
      }
    }

    .el-scrollbar::v-deep {
      // overflow: inherit;
      width: 376px;

      .el-scrollbar__wrap {
        overflow-x: visible;
      }

      .tip-usage {
        align-items: baseline;
        line-height: 18px;
        color: #79a2d0;
        background-color: #f4f9ff;
      }

      .widget-group-toggle {
        height: 56px;
        font-size: 18px;
        line-height: 56px;
        color: map-get($colors, 'grey');
        background-color: #f8f8f8;
        cursor: pointer;

        &.active {
          font-weight: bolder;
          color: map-get($colors, 'dark');
          background-color: map-get($bgColors, 'white');
        }
      }
    }

    .toggler {
      position: absolute;
      top: 50%;
      right: -20px;
      z-index: 99;
      margin-top: -20px;
      border-radius: 50%;
      width: 40px;
      height: 40px;
      background-color: #fff;
      box-shadow: 0 4px 10px 0 rgba(0, 5, 97, 0.1);
      cursor: pointer;

      .toggler-img {
        @include bg('icons/icon-double-arrow-right-cur.png');
        width: 40px;
        height: 40px;
        background-repeat: no-repeat;
        background-size: 24px;
        transition: all 0.3s;
        transform: rotate(0deg);

        &.collapse {
          transform: rotate(180deg);
        }
      }
    }
  }
</style>
